﻿using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Battle.Engine
{
    public class TableDataUtil
    {
        public int version;
        public Dict.DictDataManager dictDataManager {
            get { return Dict.DictDataManager.Instance; }
        }

        public TableDataUtil(int version = 0) {

        }




        #region GameConfigure
        /// <summary>
        /// 获取换阵超时时间
        /// </summary>
        /// <returns></returns>
        public int GetTransLimitTime() {
            return dictDataManager.tableGameConfigureDao.currentData.TransLimitTime;
        }

        /// <summary>
        /// 获得浮空持续时间
        /// </summary>
        /// <returns></returns>
        public double GetFloatDuration() {
            return dictDataManager.tableGameConfigureDao.currentData.FloatDuration;
        }

        /// <summary>
        /// 获得倒地持续时间
        /// </summary>
        /// <returns></returns>
        public double GetBreakDuration() {
            return dictDataManager.tableGameConfigureDao.currentData.BreakDuration;
        }


        /// <summary>
        /// 获得释放大招需要的怒气
        /// </summary>
        /// <returns></returns>
        public double GetUltimateCostAnger() {
            return dictDataManager.tableGameConfigureDao.currentData.UTIL_TRIGGER_ANGERCOUNT;
        }

        /// <summary>
        /// 获得怒气最大值
        /// </summary>
        /// <returns></returns>
        public double GetFighterMaxAnger() {
            return dictDataManager.tableGameConfigureDao.currentData.UTIL_MAXANGER;
        }

        /// <summary>
        /// 获得连续攻击的时间间隔（用于判断是否需要移动）
        /// </summary>
        /// <returns></returns>
        public double GetContinueAttackWaitTimeout() {
            return dictDataManager.tableGameConfigureDao.currentData.ContinueAttackWaitTimeout;
        }

        /// <summary>
        /// 获得被击怒气回复系数
        /// </summary>
        /// <returns></returns>
        public double GetBeHitAddAngerFactor() {
            return dictDataManager.tableGameConfigureDao.currentData.BeHitAddAngerPercent;
        }

        /// <summary>
        /// 获得浮空倒地状态闪避系数
        /// </summary>
        /// <returns></returns>
        public double GetFloatBreakDodgeFactor() {
            return dictDataManager.tableGameConfigureDao.currentData.FloatBreakDodgeFactor;
        }

        public double GetMagicStonePercent()
        {
            return dictDataManager.tableGameConfigureDao.currentData.BreakGetMagicStonePercent;
        }

        public string GetMagicStoneBuff()
        {
            return dictDataManager.tableGameConfigureDao.currentData.MagicStoneBuff;
        }

        /// <summary>
        /// 获得人物特殊状态间血量影响系数
        /// </summary>
        /// <param name="source">来源状态</param>
        /// <param name="target">目标状态</param>
        /// <returns></returns>
        public double GetSpecialStateHpFactor(SpeState source, SpeState target) {
            if (source == SpeState.NORMAL)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Normal2HP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Float2HP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Break2HP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2None2HP;
                }
            }
            else if (source == SpeState.FLOAT)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Normal2HP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Float2HP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Break2HP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2None2HP;
                }
            }
            else if (source == SpeState.FALL) {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Normal2HP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Float2HP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Break2HP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2None2HP;
                }
            }
            else if (source == SpeState.NONE)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Normal2HP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Float2HP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Break2HP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2None2HP;
                }
            }
            return 1;
        }

        /// <summary>
        /// 获得人物状态间攻击的怒气影响系数
        /// </summary>
        /// <param name="source">来源状态</param>
        /// <param name="target">目标状态</param>
        /// <returns></returns>
        public double GetSpecialStateApFactor(SpeState source, SpeState target) {
            if (source == SpeState.NORMAL)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Normal2AP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Float2AP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2Break2AP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Normal2None2AP;
                }
            }
            else if (source == SpeState.FLOAT)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Normal2AP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Float2AP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2Break2AP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Float2None2AP;
                }
            }
            else if (source == SpeState.FALL)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Normal2AP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Float2AP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2Break2AP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.Break2None2AP;
                }
            }
            else if (source == SpeState.NONE)
            {
                if (target == SpeState.NORMAL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Normal2AP;
                }
                else if (target == SpeState.FLOAT)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Float2AP;
                }
                else if (target == SpeState.FALL)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2Break2AP;
                }
                else if (target == SpeState.NONE)
                {
                    return dictDataManager.tableGameConfigureDao.currentData.None2None2AP;
                }
            }
            return 1;
        }

        public int GetCombohitAddNum()
        {
            return dictDataManager.tableGameConfigureDao.currentData.combohitAddNum;
        }

        public double GetCombohitdamageFactor()
        {
            return dictDataManager.tableGameConfigureDao.currentData.combohitdamageFactor;
        }

        public int GetBattleMaxRoundNum() {
            return dictDataManager.tableGameConfigureDao.currentData.fight_max_round;
        }

        /// <summary>
        /// 获得连击中断时间
        /// </summary>
        /// <returns></returns>
        public double GetComboBreakTime() {
            return dictDataManager.tableGameConfigureDao.currentData.comboBreakTime;
        }

        /// <summary>
        /// 获得自动战斗超时时间
        /// </summary>
        /// <returns></returns>
        public double GetAutoTimeout() {
            return dictDataManager.tableGameConfigureDao.currentData.autobattle_watitimer;
        }

        /// <summary>
        /// 获得普通技能CD（小回合）
        /// </summary>
        /// <returns></returns>
        public int GetNormalSkillCoolDown() {
            return dictDataManager.tableGameConfigureDao.currentData.SKILL_Round_CoolDown;
        }

        /// <summary>
        /// 获得大招技能CD（小回合）
        /// </summary>
        /// <returns></returns>
        public int GetUltimateSkillCoolDown() {
            return dictDataManager.tableGameConfigureDao.currentData.UTL_Round_CoolDown;
        }

        /// <summary>
        /// 获得大招的施法前准备时间
        /// </summary>
        /// <returns></returns>
        public double GetUltimateMoveToSkillTime() {
            return dictDataManager.tableGameConfigureDao.currentData.ultMoveToSkillTime;
        }

        /// <summary>
        /// 获得普通技能的施法前准备时间
        /// </summary>
        /// <returns></returns>
        public double GetNormalMoveToSkillTime(int heroClass) {
            if (heroClass == (int)HeroClass.Hero || heroClass == (int)HeroClass.Main_Actor_Man || heroClass == (int)HeroClass.Main_Actor_Woman)
            {
                return dictDataManager.tableGameConfigureDao.currentData.moveToSkillTime;
            }
            else if (heroClass == (int)HeroClass.Monster)
            {
                return dictDataManager.tableGameConfigureDao.currentData.monsterMoveSkillTime;
            }
            else {
                return dictDataManager.tableGameConfigureDao.currentData.moveToSkillTime;
            }

        }

        /// <summary>
        /// 获得大招施放完毕后的延时反应时间 
        /// </summary>
        /// <returns></returns>
        public double GetUltimateEndCameraTime() {
            return dictDataManager.tableGameConfigureDao.currentData.UltimateEndCameraTime;
        }

        /// <summary>
        /// 获得回合开始时显示阶段的时间（秒）
        /// </summary>
        /// <returns></returns>
        public double GetShowCampTime() {
            return dictDataManager.tableGameConfigureDao.currentData.ShowCampTime;
        }


        public double GetCopyEnemyAIDeltaTime() {
            return dictDataManager.tableGameConfigureDao.currentData.CopyEnemyAIDeltaTime;
        }

        public double GetPlayerAIDeltaTime() {
            return dictDataManager.tableGameConfigureDao.currentData.PlayerAIDeltaTime;
        }

        #endregion


        public TableCopyEnemy GetTableCopyEnemy(string id) {
            var data = dictDataManager.tableCopyEnemyDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableCopyEnemy");
            }
            return data;
        }

        public TableHero GetTableHero(string id) {
            var data = dictDataManager.tableHeroDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableHero");
            }
            return data;
        }

        public TableBuff GetTableBuff(string id) {
            var data = dictDataManager.tableBuffDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableBuff");
            }
            return data;
        }

        public TableSkill GetTableSkill(string id) {
            var data = dictDataManager.tableSkillDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableSkill");
            }
            return data;
        }

        public TableSkillCast GetTableSkillCast(string id) {
            var data = dictDataManager.tableSkillCastDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableSkillCast");
            }
            return data;
        }

        public List<TableSkillCast> GetTableSkillCastBySkillId(string skillId) {
            var data = dictDataManager.tableSkillCastDao.GetByOneIndex(skillId);
            return data;
        }

        public TableTalent GetTableTalent(string id) {
            var data = dictDataManager.tableTalentDao.GetById(id);
            if (data == null) {
                Debug.LogError("[TableDataUtil] ID:" + id + " not exist in TableTalent");
            }
            return data;
        }

    }
}
